package com.zhanghe.study.study_scala.oop

/**
 * 类型检查
 * @author zh
 * @date 2021/5/2 14:12
 */
object TestType {
  def main(args: Array[String]): Unit = {

    // classOf获取类 相当于java中的Tiger.class
    val clazz:Class[Tiger] = classOf[Tiger]
    // class com.zhanghe.study.study_scala.oop.Tiger
    println(clazz)
    val tiger:Animal = new Tiger
    // class com.zhanghe.study.study_scala.oop.Tiger
    println(tiger.getClass)
    println(clazz == tiger.getClass)
    // true 相当于java中instanceof
    println(tiger.isInstanceOf[Animal])
    // true
    println(tiger.isInstanceOf[Tiger])

    if(tiger.isInstanceOf[Tiger]){
      tiger.asInstanceOf[Tiger].run
    }
  }
}
